<layout name="layout" />

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<span id="refresh" onclick="location.href=location.href">
			
		</span>
		<a href="{:U('lunbo_add')}">添加</a>
		<table border="" cellspacing="" cellpadding="">
			<tr>
				<th>ID</th>
				<th>NAME</th>
				<th>Sort</th>
				<th>img</th>
				<th>Url</th>
				<th>操作</th>
			</tr>
			<volist name="data" id="row">
			<tr>
				<td>{$row[id]}</td>
				<td>{$row[name]}</td>
				<td><input type="text" name="" id="" value="{$row[sort]}" onblur="sorts(this,{$row[id]})" /></td>
				<td><img width="50" height="50" src="__UPLOADS__/{$row[img]}" /></td>
				<td>{$row[url]}</td>
				<td>
					<a href="{:U('lunbo_edit',array('id'=>$row['id']))}">编辑</a>
					<a href="javascript:;" onclick="del(this,{$row['id']})">删除</a>
				</td>
			</tr>	
			</volist>
			
		</table>
		{$total}
		<nav>
			{$page}
		</nav>
	</body>
	<script type="text/javascript">
		function sorts(obj,id){
			var val = $(obj).val();
//			console.log(val);
			$.post("{:U('ajax_sorts')}", {id:id, sort:val}, function(data){
				if(data == 1){
					$("#refresh").click();
				}else{
					alert("排序失败");
				}
			});
		}
		
		function del(obj,id){	
			$.post("{:U('ajax_del')}", {id:id}, function(data){
				if(data == 1){
					$(obj).parent().parent().remove();
				}else{
					alert("删除失败");
				}
			});
		}
	</script>
</html>
